package com.example.monitorapp.fragment


import android.content.Intent
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.navigation.Navigation
import com.example.baselib.constants.MyConstants
import com.example.baselib.fragment.BaseFragment
import com.example.loginlib.LoginActivity

import com.example.monitorapp.R
import com.example.monitorapp.viewmodel.UserInfoViewModel
import com.tencent.bugly.beta.Beta
import kotlinx.android.synthetic.main.fragment_user_info.*

/**
 * A simple [Fragment] subclass.
 */
class UserInfoFragment : BaseFragment<UserInfoViewModel>() {
    override fun providerVMClass(): Class<UserInfoViewModel>? {
        return UserInfoViewModel::class.java
    }

    override fun contentLayout(): Int {
        return R.layout.fragment_user_info
    }

    override fun initView() {
        user_tel_cly.setOnClickListener {
            Navigation.findNavController(it)
                .navigate(R.id.action_userInfoFragment_to_bindTelFragment)
        }

        user_pwd_cly?.setOnClickListener {
            Navigation.findNavController(it)
                .navigate(R.id.action_userInfoFragment_to_changePwdFragment)
        }
        user_exit_btn?.setOnClickListener {
            if (!isFastClick()){
                val intent = Intent(activity, LoginActivity::class.java)
                intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
                startActivity(intent)
            }
        }
        user_version_cly?.setOnClickListener {
            Toast.makeText(activity,"请稍候..",Toast.LENGTH_SHORT).show()
            Beta.checkAppUpgrade()
        }
    }

    override fun initData() {

    }

    override fun onResume() {
        super.onResume()
        viewModel.getUserData().observe(this, Observer {
            user_company_txt.text = MyConstants.userData.useridname
            user_code_txt.text = MyConstants.userData.code
            user_username_txt.text = MyConstants.userData.username
            user_tel_txt.text = MyConstants.userData.tel
            user_zw_txt.text = MyConstants.userData.post
        })
    }

}
